import TopManual from '@/pages/topManual/topManual.vue';
import OutLineManual from '@/pages/outLineManual/outLineManual.vue';
import EditorManual from '@/pages/editorManual/editorManual.vue';
import ContentCenter from '@/pages/contentCenter/contentCenter.vue';

/* eslint-disable */

import Vue from "vue";
import $ from "jquery";

export default {
    components: {
        TopManual,
        OutLineManual,
        EditorManual,
        ContentCenter
    },

    data() {
        return {
            baseConfig: null,

            loading: false,
        }
    },

    created() {

        const _this = this;

        this.baseConfig = Vue.prototype.baseConfig;

        this.$root.$on("haloLoaded", _this.createEvent);

        this.$root.$on("fileOnChanged", () => _this.loading = true);
        this.$root.$on("fileParsed", (fileName) => _this.loading = false);
        this.$root.$on("fileParsing", (fileName) => _this.loading = true);

        ['dragleave', 'drop', 'dragenter', 'dragover'].forEach(e => {
            this.preventDefaultEvent(e);
        });

        this.onClickedScene();
    },

    methods: {

        onClickedScene () {

            $(window).mousedown((e) => {

                if ($(e.target).hasClass("optionPicker selectBox")) return;
                if ($(e.target).parent().hasClass("optionList")) return;
                if ($(e.target).hasClass("texturesPickView")) return;
                if ($(e.target).parent().hasClass("texturesPickView")) return;
                if ($(e.target).parent().hasClass("texturesPickContent")) return;
                if ($(e.target).hasClass("uploadFileView")) return;
                if (($(e.target).parents(".uploadFileView")).length > 0) return;

                const optionList = $(".optionPicker .optionList");
                const uploadFileView = $(".scenesView .uploadFileView");

                if (optionList.length > 0) {
                    optionList.fadeOut(300).parent().find(".el-icon-arrow-down").removeClass("selectedType");
                }

                if (uploadFileView.length > 0) {
                    uploadFileView.fadeOut(300, () => uploadFileView.remove());
                }
            });
        },

        createEvent () {

            const _this = this;

            const eventMap = {
                AmbientLight: "AmbientLightValueChanged",
                DirectionalLight: "DirectionalLightValueChanged",
                PointLight: "PointLightValueChanged",
                SpotLight: "SpotLightValueChanged",
                HemisphereLight: "HemisphereLightValueChanged",
                RectAreaLight: "RectAreaLightValueChanged",

                PerspectiveCamera: "PerspectiveCameraValueChanged",

                Group: "GroupValueChanged",

                Mesh: "MeshValueChanged",
            };

            // eslint-disable-next-line
            Editor.Signal_Modify.add((resObj) => {

                const eventMapItem = eventMap[resObj.object.type];

                if (eventMapItem) {

                    _this.$root.$emit(eventMapItem);
                }


            });
        },

        preventDefaultEvent (eventName) {
            document.addEventListener(eventName, function (e) {
                e.preventDefault();
            }, false)
        },
    }
}